package rent.hj.launcher;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by admin on 2017/12/19.
 */

public class Code {
    private static final String TAG = "Code";
    private Context context;

    public static final long TOW_HOURS = 1000 * 60 * 60 * 2;
    public static final long THREE_HOURS = 1000 * 60 * 60 * 3;

    public Code(Context context) {
        this.context = context;
    }

    public long get(String code) {
        long time = -1;
        AssetManager assetManager = context.getAssets();
        try {
            {
                InputStream in = assetManager.open("pw/tow_pw.txt");
                InputStreamReader inputStreamReader = new InputStreamReader(in);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                String line = null;
                while ((line = bufferedReader.readLine()) != null) {
                    if (line.equals(code)) {
                        time = TOW_HOURS;
                        break;
                    }
                }
                bufferedReader.close();
                inputStreamReader.close();
                in.close();
            }

            if (time == -1) {
                InputStream in = assetManager.open("pw/three_pw.txt");
                InputStreamReader inputStreamReader = new InputStreamReader(in);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                String line = null;
                while ((line = bufferedReader.readLine()) != null) {
                    if (line.equals(code)) {
                        time = THREE_HOURS;
                        break;
                    }
                }
                bufferedReader.close();
                inputStreamReader.close();
                in.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
            return -1;
        }

        return time;
    }
}
